
/*
 *
 * Copyright (c) 2006 P.J.Leonard
 * 
 * http://www.frinika.com
 * 
 * This file is part of Frinika.
 * 
 * Frinika is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.

 * Frinika is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.

 * You should have received a copy of the GNU General Public License
 * along with Frinika; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */

package uk.ac.bath.util;

import java.io.BufferedReader;
import java.io.IOException;
import java.util.Collection;
import java.util.Iterator;

/**
 *
 * @author pjl
 */
public class TweakReader {


    public static void readTweakValues(BufferedReader bin,Collection<Tweakable> tweaks) throws IOException {
        String line1;
        while ((line1 = bin.readLine()) != null) {
            if (line1.charAt(0) == '#') {
                continue;
            }
            String line = line1.trim();
            int n = line.indexOf('=');
            if (n == -1) {
                System.err.println(" parameter parse error >" + line);
                continue;
            }
            String tweakName = line.substring(0, n);
            String val = line.substring(n + 1);
            Iterator iter = tweaks.iterator();
            boolean ok = false;
            while (iter.hasNext()) {
                Tweakable t = (Tweakable) iter.next();
                if (t.getLabel().equals(tweakName)) {
                    t.set(val);
                    System.out.println(t.getLabel() + "=" + val);
                    ok = true;
                    break;
                }
            }
            if (!ok) {
                System.out.println(" Tweak not found >" + tweakName);
            }
        }
    }
}
